####
#
#	Name: SharePoint O14 PreReq Script - PowerShell
#	Author: Nate Bruneau (nathbr)
#	Date: 8.25.2010
#
####

#REGION functions

function Display-EndPre(){

Write-Host "##########################################"
Write-Host "# SharePoint PreReq Script Completed"
	if ($env:restart -eq $true){
	Write-Host -ForegroundColor Red "#: Status: Reboot Required, then re-run Pre"
	} else {
	Write-Host "# Status: COMPLETED"
	$env:current = "main"
	}
Write-Host "#"
$global:endtime = get-date
Write-Host "# End Time: $global:endtime"
$timespan = New-TimeSpan -Start $global:starttime -End $global:endtime
Write-Host "# Deployment Time: $($timespan.Hours) hours, $($timespan.Minutes) minutes, $($timespan.Seconds) seconds"
Write-Host "##########################################"
}

function Display-StartPre(){

Write-Host "##########################################"
Write-Host "# SharePoint PreReq Started on $env:computername"
$global:starttime = Get-Date
Write-Host "# Start Time: $global:starttime"
$username = [Environment]::UserDomainName + "\" + [Environment]::UserName
Write-Host "# User: $username"
Write-Host "#"
Write-Host "#"
Write-Host "##########################################"
}

function Start-Logging(){

	## Create Directory
	if (Test-Path "C:\log"){
	}else{
	New-Item -path c:\ -name log -type directory | Out-Null
	}
	
	## Create Directory based on Date
	$dateformat = get-date -format "yyyy-MM-dd"
	if (Test-Path "C:\log\$dateformat"){
	}else{
	New-Item -path c:\log -name $dateformat -type directory | Out-Null
	}
	
	## Start Logging
	$hourmin = ""
	$hourmin = get-date -format "yyyy-MM-dd-hhmm"
	Start-Transcript -Path "c:\log\$dateformat\$env:computername-$hourmin-pre.rtf"
}

function Stop-Logging(){
	
	Stop-Transcript
}

#ENDREGION functions

pushd "$env:SPAutoFolder\Pre"

function Main(){

Clear-Host

$env:restart = $false
$env:current = "pre"

if ($env:logging -eq $false){
} else {
Start-Logging
}
Display-StartPre

$preScripts = @(

## General Server Configuration
".\Scripts\Powershell\set-PowerShellPolicy.ps1",			# Set Powershell Policy for Scripts to Run Properly
".\Scripts\DisableUAC\DisableUAC.ps1",						# Disables UAC for Administrators
".\Scripts\DisableIEESC\DisableIEESC.ps1",					# Diables Internet Explorer Enhanced Security
".\Scripts\CreateFolders\CreateFolders.ps1",				# Creates Folders and Setup Shares

## IIS Web Server Initial Configuration
".\Scripts\IIS\InstallIIS.ps1",								# Installs IIS, App Server, .NET, WCF
".\Scripts\IIS\ConfigureIISPath.ps1",						# Configures IIS Path
".\Scripts\IIS\RemoveDefaultWebSiteAppPool.ps1",			# Removes Default Website App Pool and Default Site

## Windows Server Configuration
".\Scripts\Security\ConfigureSG.ps1",						# Configure Server Security Groups
".\Scripts\DisableLoopback\DisableLoopback.ps1",			# Disables Loopback so you can browse to your portal via localhost
".\Scripts\IPv6\DisableIPv6.ps1",							# Disables IPv6 on Server

## Network Configuration
".\Scripts\Firewall\ConfigureFirewall.ps1",					# Configures Windows Firewall Rules

## SP2010 Specific Configuration and Installations
".\Scripts\WinHotfix\InstallWinQFE.ps1",					# Windows QFE Required Hotfix for O14
".\Scripts\Geneva\InstallGenevaFramework.ps1",				# Installs Geneva Framework
".\Scripts\SyncFramework\InstallSyncFramework.ps1",			# Installs Sync Framework
".\Scripts\FilterPack\InstallFilterPack.ps1",				# Installs Filter Pack 2.0
".\Scripts\ChartControl\InstallChartControl.ps1",			# Installs Chart Control for .NET 3.5.1
".\Scripts\WinHotfix\InstallKB976462.ps1"					# Installing QFE for SharePoint WCF Fix
)

	foreach ($script in $preScripts){

	$Execute = & $script | Out-Default
	
		if ($env:restart -eq $true){
		break
		}

	}

Display-EndPre
if ($env:logging -eq $false){
} else {
Stop-Logging
}

popd

}

Main



